package com.netease.nim.uikit.xpopup.popuview

import android.content.Context
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lxj.xpopup.util.XPopupUtils
import www.wen.com.common.R
import www.wen.com.common.lib.data.entities.AreaCodeEntity
import www.wen.com.common.lib.helper.ResultCallBack


/**
 * @author WEN
 * @Description:
 * @date 2021/8/19 14:41
 */
class BottomAreaCodeListPopupView(
        context: Context,
        private val itac: Int = 86,
        data: List<AreaCodeEntity>,
        resultCallBack: ResultCallBack<AreaCodeEntity>,
) : BaseBottomListPopupView<AreaCodeEntity>(context, data, resultCallBack) {

    override fun onCreate() {
        data.find { it.code == itac }?.isSelected = true
        super.onCreate()
    }

    override fun getImplLayoutId(): Int = R.layout.popupview_area_code

    override fun getRvAdapter(): BaseQuickAdapter<AreaCodeEntity, BaseViewHolder> = AreaCodeListAdapter()

    internal class AreaCodeListAdapter : BaseQuickAdapter<AreaCodeEntity, BaseViewHolder>(R.layout.popupview_area_code_item) {

        override fun convert(holder: BaseViewHolder, item: AreaCodeEntity) {
            holder.setText(R.id.strAreaCode, item.zh)
            holder.getView<View>(R.id.slSelectContainer).isSelected = item.isSelected
        }

    }

    override fun getMaxHeight(): Int = (XPopupUtils.getScreenHeight(context) * 0.2f).toInt()

}